{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "feac998a",
   "metadata": {},
   "source": [
    "# Iterative Quantum Phase Estimation Algorithm\n",
    "\n",
    "The goal of this tutorial is to understand how the Iterative Phase Estimation (IPE) algorithm works, why would we use the IPE algorithm instead of the QPE (Quantum Phase Estimation) algorithm and how to build it with Qiskit using the same circuit exploiting reset gate and the `c_if` method that allows to apply gates conditioned by the values stored in a classical register, resulting from previous measurements.\n",
    "\n",
    "**References**\n",
    "\n",
    "- [Section 2 of Lab 6: Iterative Phase Estimation (IPE) Algorithm](https://learn.qiskit.org/course/ch-labs/lab-6-iterative-phase-estimation-algorithm) \n",
    "\n",
    "- [Ch.3.6 Quantum Phase Estimation](https://learn.qiskit.org/course/ch-algorithms/quantum-phase-estimation)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edf04b07",
   "metadata": {},
   "source": [
    "# Conditioned gates: the ``c_if`` method"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4eb985e3",
   "metadata": {},
   "source": [
    "Before starting the IPE algorithm, we will give a brief tutorial about the Qiskit conditional method, `c_if`, as it goes into building the IPE circuit.\n",
    "\n",
    "`c_if` is a function (actually a method of the gate class) to perform conditioned operations based on the value stored previously in a classical register. With this feature you can apply gates after a measurement in the same circuit conditioned by the measurement outcome.\n",
    "\n",
    "For example, the following code will execute the $X$ gate if the value of the classical register is $0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8d3ed2e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAM4AAAB7CAYAAAA8GL8CAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAN3ElEQVR4nO3de1CU5R4H8C+7S66CIsoxAtY14jJKIiaVIAia5oWaUCFrBDyKqXiBTI9UhqehRPNyjGLG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Lmi600SExMRHBys98jJyYGHhwdKS0uh0Whw+PBhjB49GgDw4Ycf4qOPPkJSUhIAwM/PD7m5uQCg186sBDu9lPQIGo2GzZ07lwUGBrIpU6YYzC8pKWH+/v7M39/fqLOe09PTmZ+fH5s6dSqrr69nBQUFLCIigjHG2KZNm9j27dsZY4zFxsaygIAAtmTJErO+njZ0yg0hHOg7DnlkkpOTsX//ft3f06ZNs9hxFkujHocQDrRzgBAOFBxCOFBwCOFAwSGEAwWHEA4UHEI4UHAI4UDBIYQDBYcQDhQcQjhQcAjhQMEhhAMFhxAOFBxCOPwfP+MrT474IXgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 253.926x144.48 with 1 Axes>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from qiskit import QuantumCircuit\n",
    "\n",
    "qc = QuantumCircuit(1, 1)\n",
    "qc.h(0)\n",
    "qc.measure(0,0)\n",
    "qc.x(0).c_if(0, 0)\n",
    "qc.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7bb05bbd",
   "metadata": {},
   "source": [
    "We highlight that the method ``c_if`` expects as the first argument a whole classical register, not a single classical bit (or a list of classical bits), and as the second argument a value in decimal representation (a non-negative integer), not the value of a single bit, 0, or 1 (or a list/string of binary digits).\n",
    "\n",
    "Let's make another example. Consider that we want to perform a bit flip on the third qubit after the measurements in the following circuit, when the results of the measurement of $q_0$ and $q_1$ are both $1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "00b7d3a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATMAAADWCAYAAAC9pmXbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAa40lEQVR4nO3de1iUdaIH8O8M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bY+IOpfDllnv3r2hVqtRU1NzX8vfz2Hm92cv8PCUqAs9EIeZPXr0QGRkJLKzs3mvMSJy7AsAR44cQWRkJPz8/PDqq6/Cz88PVVVV2L9/P7Zu3WqXbRQdOIa/fF2CpFmT4evlaZd1EpH9OexhJgCEh4fjwIEDSE1NxeLFi9HU1ARfX18899xzdlm/0diM/Yf/iiB/XxYZkcw59J5ZZ6u9eBkf7SzEcxPHssyIZI5lZkFLSwvUaoc9tUj0wGCZEZEicJeDiBSBZUZEisAyIyJFYJkRkSKwzIhIEVhmRKQILDMiUgSWGREpAsuMiBSBZUZEisAyIyJFYJkRkSKwzIhIEVhmRKQILDMiUgSWGREpAsuMiBSBZUZEisAyIyJFYJkRkSKwzIhIEVhmRKQILDMiUgSWGREpAsuMiBSBZUZEisAyIyJF+D+qW5Vhk2IV+AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 387.597x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from qiskit import QuantumRegister, ClassicalRegister\n",
    "\n",
    "q = QuantumRegister(3, 'q')\n",
    "c = ClassicalRegister(3, 'c')\n",
    "qc = QuantumCircuit(q, c)\n",
    "\n",
    "qc.h([0, 1, 2])\n",
    "qc.barrier()\n",
    "qc.measure(q, c)\n",
    "\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae92e111",
   "metadata": {},
   "source": [
    "We want to apply the $X$ gate, only if both the results of the measurement of $q_0$ and $q_1$ are $1$. We can do this using the ``c_if`` method, conditioning the application of $X$ depending on the value passed as argument to ``c_if``.\n",
    "\n",
    "We will have to encode the value to pass to the ``c_if`` method such that it will check the values 011 and 111 (in binary representation), since it does not matter what $q_2$ is measured as.\n",
    "\n",
    "The 2 integer values in decimal representation:\n",
    "\n",
    "$$\\begin{alignedat}{2}\n",
    "\\left.\\begin{array}{ccc}2^2 & 2^1 & 2^0\\\\\\hline 0 & 1 & 1\\end{array}\\ \\right\\vert&\\ (0\\times2^2) + (1\\times2^1) + (1\\times2^0) = &&2 + 1 = 3 \\\\[10px]\n",
    "\\left.\\begin{array}{ccc}2^2 & 2^1 & 2^0\\\\\\hline 1 & 1 & 1\\end{array}\\ \\right\\vert&\\ (1\\times2^2) + (1\\times2^1) + (1\\times2^0) = 4 + {}&&2 + 1 = 7\n",
    "\\end{alignedat}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25fa9853",
   "metadata": {},
   "source": [
    "We can check the solutions using the ``bin()`` method in python (the prefix `0b` indicates the binary format)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "19b565e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0b11\n",
      "0b111\n"
     ]
    }
   ],
   "source": [
    "print(bin(3))\n",
    "print(bin(7))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4c65c39",
   "metadata": {},
   "source": [
    "So we have to apply $X$ to $q_2$ using ``c_if`` two times, one for each value corresponding to 011 and 111."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1bbd6b37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAADWCAYAAAAtmd5RAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAhEElEQVR4nO3de1iUdcI+8HsGOagE6suLxkEKFAQURgHXQ8JgVFgeEdn0F790MY1w10MHafN8QEVT3g7qapZttpQgnvbFNlSYLDyAihFKLGohLCUqipiAMfP+wTIrDsw8EPB9wPtzXV7X+BzmuUcuuef5PieFTqfTgYiISAKl6ABERNRxsDSIiEgylgYREUnG0iAiIslYGkREJBlLg4iIJGNpEBGRZCwNIiKSjKVBRESSsTSIiEgylgYREUnG0i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3NMgIiLJWBpERCQZS4OIiCRjaRARkWQsDSIikoylQUREkrE0iIhIMpYGERFJxtIgIiLJWBpERCQZS4OIiCRjaRARkWQsDSIikoylQUREkrE0iIhIMpYGERFJxtIgIiLJ/g/LPUw7nBVLagAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 507.997x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc.x(2).c_if(c, 3) # for the 011 case\n",
    "qc.x(2).c_if(c, 7) # for the 111 case\n",
    "\n",
    "qc.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a50c886",
   "metadata": {},
   "source": [
    "# IPE\n",
    "\n",
    "The motivation for using the IPE algorithm is that QPE algorithm works fine for short depth circuits but when the circuit starts to grow, it doesn't work properly due to gate noise and decoherence times.\n",
    "\n",
    "The detailed explanation of how the algorithm works can be found in [Iterative Phase Estimation (IPE) Algorithm](https://learn.qiskit.org/course/ch-labs/lab-6-iterative-phase-estimation-algorithm). To understand QPE in depth, you can see also [Ch.3.6 Quantum Phase Estimation](https://learn.qiskit.org/course/ch-algorithms/quantum-phase-estimation).\n",
    "\n",
    "## IPE example with a 1-qubit gate for $U$\n",
    "\n",
    "We want to apply the IPE algorithm to estimate the phase for a 1-qubit operator $U$.  For example, here we use the $S$-gate.\n",
    "\n",
    "Let's apply the IPE algorithm to estimate the phase for $S$-gate.\n",
    "Its matrix is \n",
    "$$ S = \n",
    "\\begin{bmatrix}\n",
    "1 & 0\\\\\n",
    "0 & e^\\frac{i\\pi}{2}\\\\ \n",
    "\\end{bmatrix}$$\n",
    "\n",
    "That is, the $S$-gate adds a phase $\\pi/2$ to the state $|1\\rangle$, leaving unchanged the phase of the state $|0\\rangle$\n",
    "\n",
    "$$ S|1\\rangle = e^\\frac{i\\pi}{2}|1\\rangle $$\n",
    "\n",
    "In the following, we will use the notation and terms used in [Section 2 of lab 6](https://learn.qiskit.org/course/ch-labs/lab-6-iterative-phase-estimation-algorithm#lab-15-0).\n",
    "\n",
    "Let's consider to estimate the phase $\\phi=\\frac{\\pi}{2}$ for the eigenstate $|1\\rangle$, we should find $\\varphi=\\frac{1}{4}$ (where $\\phi = 2 \\pi \\varphi$). Therefore to estimate the phase we need exactly 2 phase bits, i.e. $m=2$, since $1/2^2=1/4$. So $\\varphi=0.\\varphi_1\\varphi_2$.\n",
    "\n",
    "Remember from the theory that for the IPE algorithm, $m$ is also the number of iterations, so we need only $2$ iterations or steps.\n",
    "\n",
    "First, we initialize the circuit. IPE works with only 1 auxiliary qubit, instead of $m$ counting qubits of the QPE algorithm. Therefore, we need 2 qubits, 1 auxiliary qubit and 1 for the eigenstate of $U$-gate, and a classical register of 2 bits, for the phase bits $\\varphi_1$, $\\varphi_2$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c82b1da1",
   "metadata": {},
   "outputs": [],
   "source": [
    "nq = 2\n",
    "m = 2\n",
    "q = QuantumRegister(nq, 'q')\n",
    "c = ClassicalRegister(m, 'c')\n",
    "\n",
    "qc_S = QuantumCircuit(q,c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fead17a6",
   "metadata": {},
   "source": [
    "### First step\n",
    "\n",
    "Now we build the quantum circuit for the first step, that is, the first iteration of the algorithm, to estimate the least significant phase bit $\\varphi_m$, in this case $\\varphi_2$. For the first step we have 3 sub-steps:\n",
    "- initialization\n",
    "- application of the Controlled-$U$ gates\n",
    "- measure of the auxiliary qubit in X-basis\n",
    "\n",
    "#### Initialization\n",
    "\n",
    "The initialization consists of application the Hadamard gate to the auxiliary qubit and the preparation of the eigenstate $|1\\rangle$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b0eb6f14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH0AAACoCAYAAADNc+G5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb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4ijE8TRCeLoBHF0gjg6QRydII5OEEcniKMTxNEJ4uiDePDgAZYsWYK5c+fCaDRi9+7dSo8kK44+CD8/P+zfvx+3bt3C1atXUV9fj9OnTys9lmz4x6UGERYWhrCwMABAQEAAkpOT0d7ervBU8uGVPozOzk7U1NRg6dKlSo8iG47+PXp6epCdnY3t27djzpw5So8jG/7ByCG43W7k5OQgMjIShw4dUnocWXH0IZjNZng8HpSXl/t8ZJfacfRBXLx4EYsWLUJ8fDx0Oh0AYOPGjdi2bRskSdL8BwFH91Ht3+1wu93IWrZIs/H5CzkfPHvuwqVrLZpf7ZqPfuPGDaxevRqhoaEIDAxEbGws9uzZMyrPsv7jGiRJwuIfJ4/K/ceKprf3y5cvIz09HRERESgqKkJUVBQcDgfsdjuOHz/+vX/24/2fj9GUY+OzIu/Pv9f0K3K7du3C5MmTcenSJUydOrX/utlsVnAq9dPsSn/58iWCg4OxdetWHDlyZFSf9ey5Cwc//wop8QasyvTttGk10uxK7+rqgsfjgV6vH/43D2Ik23tj8200Nt8e0fNGmy/bu2a/kAsJCYEoiujo6FB6FM3R7PYO9P33Hi0tLbhz5w6mTJkyKs+o+Ws9Gptv4aOCXIRMVe6AAjlpdqUDQFlZGVwuF1JTU1FRUYG6ujqcOHECmzZtkuX+z5678M/rt7EgIW7cBAc0/Dkd6Dv3vaGhAcXFxdixYwdev36NiIgI5ObmynL/p8+eI3jyJM1/X/42TW/vY8Hj8UBUwcH8cuLoBI2vD2HmFY5OEEcniKMTxNEJ4ugEcXSCODpBHJ0gjk4QRyeIoxPE0Qni6ARxdII4OkEcnSCOThBHJ4ijE8TRCeLoBHF0gjg6QRydII5OEEcn6L+kuQV9V0jLqwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 146.652x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_S.h(0)\n",
    "qc_S.x(1)\n",
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30757254",
   "metadata": {},
   "source": [
    "#### Application of the Controlled-$U$ gates\n",
    "\n",
    "Then we have to apply $2^t$ times the Controlled-$U$ operators (see also in the docs [Two qubit gates](https://qiskit.org/documentation/tutorials/circuits/3_summary_of_quantum_operations.html#Two-qubit-gates)), that, in this example, is the Controlled-$S$ gate ($CS$ for short).\n",
    "\n",
    "To implement $CS$ in the circuit, since $S$ is a phase gate, we can use the controlled phase gate $\\text{CP}(\\theta)$, with $\\theta=\\pi/2$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4629d696",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKoAAAB7CAYAAADkFBsIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAIK0lEQVR4nO3dW0xU+R3A8e8MC8KWrcWQYsSIIowKkUHxFmK51OqiL9h4t0yiIdGI2kTb6kOD7Ut5IJPGtMHGpgYTH2iUkE2aGFI2wiBC6rWD2rqjQURdBNSyLlRQYfow67AoF+mGc85v+H2SCXBgwm/CN+fMmXDmb/P7/X6Usji72QMo9SE0VCWChqpE0FCVCBqqEkFDVSJoqEoEDVWJoKEqETRUJYKGqkTQUJUIGqoSQUNVImioSgQNVYmgoSoRNFQlgoaqRNBQlQgaqhJBQ1UiaKhKBA1ViaChKhE0VCWChqpE0FCVCBqqEkFDVSJoqEoEDVWJoKEqETRUJYKGqkTQUJUIGqpAgwPQ3wsDr8yexDiWDnVwcBC3201ycjKRkZE4nU48Hg8LFixgz549Zo9nuL4XcOdzqPsjXPwT1P4BblTB8zazJ5t8H5k9wFgKCwupqqqiuLiYjIwMGhsb2bFjB11dXRw+fNjs8QzV8xSu/RVe9w3f/uw+PGuBRZ9C/GJzZjOCZUOtqKjg9OnT1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BA1ViaChKhE0VCWChqpE0FCVCBqqEkFDVSJoqEoEDVWJoKEqETRUJYKGqkTQUJUIGqoSQUNVImioSgQNVYmgoSoRNFQlgoaqRNBQlQj/A08ZhshjQJjAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 206.852x144.48 with 1 Axes>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from math import pi\n",
    "\n",
    "cu_circ = QuantumCircuit(2)\n",
    "cu_circ.cp(pi/2, 0, 1)\n",
    "cu_circ.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a09a586",
   "metadata": {},
   "source": [
    "Let's apply $2^t$ times $\\text{CP}(\\pi/2)$. Since for the first step $t=m-1$, and $m=2$, we have $2^t=2$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3e94b96d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATIAAACoCAYAAABjTGJUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAP40lEQVR4nO3de3BUZZ7G8W93JxAkgGEyIsQQiLkAgQQIo5Bic9FBobZ2QynXXVIWxgrDZbUoGR2LwX9wUwpZp9wtXZ0pBMutAQdWkZoCd7FMAoEIcgugsGFMICQwhju0QEi6z/7REs2YKyZ9zts8n6q3pM853e+vX+Hp9z3pnOOyLMtCRMRgbrsLEBH5qRRkImI8BZmIGE9BJiLGU5CJiPEUZCJiPAWZiBhPQSYixlOQiYjxFGQiYjwFmYgYT0EmIsZTkImI8RRkImI8BZmIGE9BJiLGU5CJiPEUZCJiPAWZiBhPQSYixlOQiYjxFGQiYjwFmYgYT0EmIsZTkImI8RRkImK8MLsLcLoP90HdJXv6jomCJybY07eISRRkHai7BF/X212FiLRHS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YjDGB9kR44c4cknnyQ6OpqIiAgSExNZvnx5j/RV8vkhLMsiZ9K4Hnl9EbkzRi8t9+/fT2ZmJrGxsbz44ovExcVRXV3N7t27WbNmTbvP/c1rvw9SlSJyp159saBTxxn9zf7nn3+evn37smfPHgYMGNC8PT8/38aqRCTYjJ2RXb9+nX79+rFkyRLeeOONHu3r8lUvq3+/gfTRSTwxNbNH+xKRrjN2Rnbp0iX8fj8PPPDAHT3/TpaWeyuOs7fi+B31JyJd19mlpbEn+6OionC73dTV1dldiojYzNilJUBOTg5fffUVJ06coH///j3Sx+b/LWNvxTF+XTCHqAH9eqQPEflpjJ2RARQVFeH1epk4cSLr1q2juLiY9957j2eeeaZbXv/yVS9fHD7OhDHJCjERBzP2HBlAeno65eXlrFixgqVLl3Lz5k1iY2OZM2dOt7z+hctX6df3Hn1vTMThjF5aBoPf78ftNnriKhLyFGQiYjxNNUTEeAoyETGegkxEjKcgExHjKchExHgKMhExnoJMRIynIBMR4ynIRMR4CjIRMZ6CTESMpyATEeMpyETEeAoyETGegkxEjKcgExHjKchExHgKMhExnoJMRIynIBMR4ynIRMR4CjIRMZ6CTESMpyATEeMpyETEeAoyETGegkxEjPf/L0zxZl/8r40AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 387.452x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for _ in range(2 ** (m - 1)):\n",
    "    qc_S.cp(pi/2, 0, 1)\n",
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db469592",
   "metadata": {},
   "source": [
    "#### Measure in X-basis\n",
    "\n",
    "Finally, we perform the measurement of the auxiliary qubit in X-basis. So we will define a function to perform the ``x_measurement`` and then apply it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "aa1cd4fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def x_measurement(qc, qubit, cbit):\n",
    "    \"\"\"Measure 'qubit' in the X-basis, and store the result in 'cbit'\"\"\"\n",
    "    qc.h(qubit)\n",
    "    qc.measure(qubit, cbit)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e4417ce",
   "metadata": {},
   "source": [
    "In this way we obtain the phase bit $\\varphi_2$ and store it in the classical bit $c_0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9d767f96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAACoCAYAAAAcsbLgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUuUlEQVR4nO3df1RUdf7H8ecMPwQFUyN/gPgDARUUUNhWKQXyW+npW7bmz76xrV9cXdNzzJPbz23/cfNsLvW1zumHu4ta28lt1TLzmJvfE6AmaZgSZn0xwRBkw58ZoYDMfP+YlUKB+WAwdwZfj3M+58x87p1733N15jWfz53L2JxOpxMREREDdqsLEBER36HQEBERYwoNERExptAQERFjCg0RETGm0BAREWMKDRERMabQEBERYwoNERExptAQERFjCg0RETGm0BAREWMKDRERMabQEBERYwoNERExptAQERFjCg0RETGm0BAREWMKDRERMabQEBERYwoNERExptAQERFjCg0RETGm0BAREWMKDRERMabQEBERY/5WF+Dt3i6EyrPW7DuiN0xLsWbfIt7GV1+LDz/8MAcPHuzQekwkJSWxatWqDt+uQsONyrNwtNrqKkTEV1+LBw8eJD8/3+oyOoymp0RExJhCQ0REjCk0RETEmEJDRESMKTRERMSYQkNERIzpK7ciIl4mNDSUUaNGERISQn19PSUlJVRVVbW6/qRJk6itraWgoKDTa1NoiIh4gZtuuomsrCx++ctfMnLkyKuWV1VVsWnTJl555RUOHz7c1D9p0iTee+89GhoaSE5O5quvvurUOhUa0umcTjhbDmeOg9MBPfvCTTFg97O6sq7H6YBTZfDtCdf9G8IhbCjY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kLIzMzssBptTr0LtsuW/91DY2Mj995xKzabzepyRKQLenv7TvYVfdl0v19YbxY/+AsC/K3/7pJGGu1w7nwNew8exul0KjBEpNPcddt4buzVEwA/u51Z/5nhFYEBXSA0iouLue+++wgLCyMoKIiYmBieeuqpTtlX3scHcTqdZIwf0ynbFxEB6BYYwMy70rHZbNw+IYXwfmFWl9TEp6en9u/fz8SJE4mMjOSxxx5j8ODBlJWVsWfPHnJyctp87OPP/tlDVYqIeL8/PjbfaD3vGO9co0ceeYQePXqwd+9ebrjhhqb+rKwsC6sSEem6fHakUVtbS2hoKIsXL+aFF17o1H2dO1/Dn/78d5JHxTJt8sRO3ZeIiDfz2ZHG2bNncTgc13zRyrVMT+0r+rLZNxpERLoK0+kpnz0R3rt3b+x2O5WVlVaXIiJy3fDZ6SmAjIwMDh8+zJEjR+jZs2en7GPzB7vZV/QFv50/m943hHbKPkREfIXPjjQAsrOzqampYdy4caxbt47c3Fxee+015s2b1yHbP3e+hk8++5KU0cMVGCIi+PA5DYDk5GQKCgp4+umnWbp0KRcvXiQyMpLZs2d3yPZPnztPaI/uui5DROTffHp6yhMcDgd2u08PyEREOoxCQ0REjOkjtIiIGFNoiIiIMYWGiIgYU2iIiIgxhYaIiBhTaIiIiDGFhoiIGFNoiIiIMYWGiIgYU2iIiIgxhYaIiBhTaIiIiDGFhoiIGFNoiIiIMYWGiIgYU2iIiIgxhYaIiBhTaIiIiDGFhoiIGFNoiIiIMYWGiIgYU2iIiIgxhYaIiBhTaIiIiDGFhoiIGFNoiIiIMYWGiIgY+38bkksB4oM9EwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 507.852x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_measurement(qc_S, q[0], c[0])\n",
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99727bfd",
   "metadata": {},
   "source": [
    "### Subsequent steps (2nd step)\n",
    "\n",
    "Now we build the quantum circuit for the other remaining steps, in this example, only the second one.\n",
    "In these steps we have 4 sub-steps: the 3 sub-steps as in the first step and, in the middle, the additional step of the phase correction\n",
    "- initialization with reset\n",
    "- phase correction\n",
    "- application of the Control-$U$ gates\n",
    "- measure of the auxiliary qubit in X-basis\n",
    "\n",
    "#### Initialization with reset\n",
    "\n",
    "As we want to perform an iterative algorithm in the same circuit, we need to reset the auxiliary qubit $q_0$ after the measument gate and initialize it again as before to recycle the qubit. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c69ed53a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAegAAACoCAYAAAArf33UAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAW8klEQVR4nO3dfVBU96HG8e8u7wr4RuIrogTQgAIqTcRGgdgYndxKb16M9oamXqzW6IxxYqKNTTsdWxst6U0607TmlmiSTmyv2ERjE2/tREiMVsUqYkwuRlDE0GJURKICsnv/2LoJEdhFYc9v4fnMnHH3d87ueTju8uw5e3axOZ1OJyIiImIUu9UBRERE5HoqaBEREQOpoEVERAykghYRETGQClpERMRAKmgREREDqaBFREQMpIIWERExkApaRETEQCpoERERA6mgRUREDKSCFhERMZAKWkRExEAqaBEREQOpoEVERAykghYRETGQClpERMRAKmgREREDqaBFREQMpIIWERExkApaRETEQCpoERERA6mgRUREDKSCFhERMZAKWkRExEAqaBEREQMFWh3AdH8qhtPnrVn30H5wf5o16xYxjb8+Fx9//HEOHTrUqXm8kZqayvPPP39Dt7UqM9xcbqseI131u1oF7cHp83C8xuoUIuKvz8VDhw5RVFRkdYwO8cfM4L+PkbboELeIiIiBVNAiIiIGUkGLiIgYSAUtIiJiIBW0iIiIgVTQIiIiBtLHrEREDBMREcGYMWMIDw+ns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LB7927y8/Pbve2KNS/5KKWIiMgXnl0+36vl/PqYyRNPPEHv3r3Zu3cvffr0cY/n5uZamEpEROTm+e0e9KVLl4iIiGDx4sW88MILXbqu2rp6fvHSH5gwJoH7p0/p0nWJiIiAH+9Bnz9/HofDccMfwL+RQ9z7Sj5ucWaliIhIR3l7iNtvTxLr168fdrud06dPWx1FRESk0/ntIW6ArKwsjh49yrFjx4iMjOySdbz5l13sK/mIJ+fPpl+fiC5Zh4iIyFf57R40QF5eHvX19UycOJENGzawc+dOXnnlFebNm9cp919bV8/+wx+TNnaUyllERHzKb9+DBpgwYQJ79uzhmWeeYenSpVy5coXo6Ghmz57dKfd/traOiN699LlnERHxOb8+xO0LDocDu92vDzSIiIgfUkGLiIgYSLuGIiIiBlJBi4iIGEgFLSIiYiAVtIiIiIFU0CIiIgZSQYuIiBhIBS0iImIgFbSIiIiBVNAiIiIGUkGLiIgYSAUtIiJiIBW0iIiIgVTQIiIiBlJBi4iIGEgFLSIiYiAVtIiIiIFU0CIiIgZSQYuIiBhIBS0iImIgFbSIiIiBVNAiIiIGUkGLiIgYSAUtIiJiIBW0iIiIgVTQIiIiBlJBi4iIGEgFLSIiYqD/BxUPdimeXFp3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 628.252x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_S.reset(0)\n",
    "qc_S.h(0)\n",
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60060d00",
   "metadata": {},
   "source": [
    "#### Phase correction (for step 2)\n",
    "As seen in the theory, in order to extract the phase bit $\\varphi_{1}$, we perform a phase correction of $-\\pi\\varphi_2/2$.\n",
    "Of course, we need to apply the phase correction in the circuit only if the phase bit $\\varphi_2=1$, i.e. we have to apply the phase correction of $-\\pi/2$ only if the classical bit $c_0$ is 1.\n",
    "\n",
    "So, after the reset we apply the phase gate $P(\\theta)$ with phase $\\theta=-\\pi/2$ conditioned by the classical bit $c_0$ ($=\\varphi_2$) using the `c_if` method.\n",
    "So as we saw in the first part of this tutorial, we have to use the `c_if` method with a value of 1, as $1_{10} = 001_{2}$ (the subscripts $_{10}$ and $_2$ indicate the decimal and binary representations)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4d7b8a7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAACoCAYAAAC8GKf/AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAbdElEQVR4nO3df1xUdaL/8dcMIKD88AelooiigoEKKlvihoC/0kc3KSvT0tt6dXFNH1/zoZabtd29lqsutbV7a9d2Ncvd3Fbd1Cy92Sak4S9M8VcuKiiibJgKSCooM98/ZsVQfuphzgy+n4/HecScOTPnzWkG3/OZM5+x2O12OyIiIiIGsJodQERERJoOFQsRERExjIqFiIiIGEbFQkRERAyjYiEiIiKGUbEQERERw6hYiIiIiGFULERERMQwKhYiIiJiGBULERERMYyKhYiIiBhGxUJEREQMo2IhIiIihlGxEBEREcOoWIiIiIhhVCxERETEMCoWIiIiYhgVCxERETGMioWIiIgYRsVCREREDKNiISIiIoZRsRARERHDqFiIiIiIYVQsRERExDAqFiIiImIYFQsRERExjKfZAVzd3zPh1Hlz9t2hFYyKNWffIq7GXZ+Lzz77LHv37jU0T33ExMTwxhtv3NJtzcoMt5fbrMfI7Tw+/vkFXCg0Nk99+d8NEYOMv18VizqcOg/HTPqfLiLXuetzce/evaSnp5sdo0HcMTO452PkQiEU5Zudwlh6K0REREQMo2IhIiIihlGxEBEREcOoWIiIiIhhVCxERETEMPpUiIiIiBuZ+ftEvjmxDQ8PL6xWD9q3DuOpwS8S3/tRs6MBKhYiIi7H39+fnj174ufnR3l5OdnZ2RQUF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cmzo4iIiDSqgMBWdOzcvdZPJFosFrqER9K8hZ8Tk1WTw13fCgFISkri0KFDHDlyhICAgEbZx5rPtrIz6xtmp4yhVaB/o+xDRESkLp9//jkPPPAAdrv9phM4LRYLFouFtLQ04uPjTUro4LYjFgCpqamUlpbSv39/li1bxubNm3nvvfeYNGmSIfdfVFLKrn2Hie0VoVIhIiKmGjJkCMuXL8fLywsAq9WKh4cHAN7e3nz44Yemlwpw43MsAPr168e2bdt46aWXmDFjBpcvXyYkJIQxY8YYcv9ni0rwb9Fc81aIiIhLePLJJxk6dChLly5l+/btWK1W4uLimDBhAm3atDE7HuDmb4U4g81mw2p164EdERERp1GxEBEREcPopbiIiIgYRsVCREREDKNiISIi4uJmzJhBfHw806dPr/b6DRs20KNHD+6//34nJ7uZioWIiIgL+/rrryktLWXLli2Ul5eza9eum7bp378/WVlZJqS7mYqFiIiIC9u+fTtDhw4FHHNZbNu2jdmzZ2Oz2Rg+fDh5eXm0atUKb29vk5M6qFiIiIi4sKKiosrZpQMDAykqKuLbb78lJSWFhx56iE6dOpmcsCq3niBLRESkqQsMDKSkpASAkpISWrZsyeTJkxkxYgRvvfWWyeluphELERERFxYXF8c//vEPwPF9If3792fevHm8/PLLLFiwwOR0N1OxEBERcWF9+/bFx8eH+Ph4PDw8yMjI4JFHHmHmzJns37+fgwcPkpmZyZAhQzhw4ABDhgzh8uXLpuXVzJsiIiJiGI1YiIiIiGFULERERMQwKhYiIiJiGBULERERMYyKhYiIiBhGxUJEREQMo2IhIiIihlGxEBEREcOoWIiIiIhhVCxERETEMCoWIiIiYhgVCxERETGMioWIiIgYRsVCREREDKNiISIiIoZRsRARERHDqFiIiIiIYf4/Q2yTWN7ZqxQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 688.452x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_S.p(-pi/2, 0).c_if(c, 1)\n",
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b096b64",
   "metadata": {},
   "source": [
    "#### Application of the Control-$U$ gates and x-measurement (for step 2)\n",
    "\n",
    "We apply the $CU$ operations as we did in the first step. For the second step we have $t=m-2$, hence $2^t=1$. So we apply $\\text{CP}(\\pi/2)$ once. And then we perform the X-measurement of the qubit $q_0$, storing the result, the phase bit $\\varphi_1$, in the bit $c_1$ of classical register."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8d0b95ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 2^t c-U operations (with t=m-2)\n",
    "for _ in range(2 ** (m - 2)):\n",
    "    qc_S.cp(pi/2, 0, 1)\n",
    "\n",
    "x_measurement(qc_S, q[0], c[1]) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02d9b94c",
   "metadata": {},
   "source": [
    "Et voilà, we have our final circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "31d410f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAssAAACoCAYAAAAW96MGAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAhhklEQVR4nO3deVgUh+H/8c8ut4KKYkTECxUVRPBoKkYEvH3SaGsSj6hN/Gq0RvuzPuZqTNpvv7bmqGmbtkmaNuayzVE1jcZEWxOFaDAqRhE1FiMoYkg8EBEVEHZ/f2zEoAy7KDC76/v1PPOEnZnd+bgZZj/MzmGx2+12AQAAALiG1ewAAAAAgLuiLAMAAAAGKMsAAACAAcoyAAAAYICyDAAAABigLAMAAAAGKMsAAACAAcoyAAAAYICyDAAAABigLAMAAAAGKMsAAACAAcoyAAAAYICyDAAAABigLAMAAAAGKMsAAACAAcoyAAAAYICyDAAAABigLAMAAAAGKMsAAACAAcoyA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LAMAAAAGKMsAAACAAcoyAAAAYICyDAAAABigLAMAAAAGKMsAAACAgf8PHEKOIjI+llIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 929.252x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc_S.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5b1356c",
   "metadata": {},
   "source": [
    "Let's sample the circuit with Qiskit Aer's `Sampler` primitive, a local simulator without noise that runs locally."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1c984758",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcgklEQVR4nO3de5QddZXo8e/mJTJERkADCYaHtiAookQCzAUaBxTxLhbKXJAREVwSI4oio1dcV0dRwCUiwkVZCo5iGJxhwBeOICiXBpQAJgryElGeCSEQiIAYCIZ9/6hqPTT9qOqc7lPn9PezVq2cU/WrOvtIb/epX1X9fpGZSJLUNGt1OgBJkoZjgZIkNZIFSpLUSBYoSVIjWaAkSY1kgZIkNdI6nQ6gkzbddNPcaqutOh1GR91zzz089thjrLPOOuywww7P256Z3H///Tz++OOstdZabLXVVmywwQYdiLR5Fi1atDwzX9LpOJrAXDKX1sSIuZSZU3bZeeedc6q76qqrctGiRbnDDjsMu/3HP/5x7rfffvnss8/mggULcpdddpnkCJsLWJgN+DtuwmIumUtrYqRcsotvittzzz3ZeOONR9z+wx/+kMMPP5yIYNddd+WPf/wjS5cuncQIpe5gLrWfBUqjWrJkCS972cv++n6LLbZgyZIlHYxI6k7mUn0WKElSI1mgNKqZM2dy//33//X94sWLmTlzZgcjkrqTuVSf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4pK5gF58kTbDyeadvAL+yOFXnGZQkTaDyZolny4kKt8zMWzsdU7ewQElSG5VDGa1FMdrR4OCwLynv6FMNdvFJUhtERF9EvDQLrSOv7AVcHREf62R83cix+CRpnMoHcd8FfAR4GPhLRCylmAvqe5n5JMWJwJ+AuzoWaJeyi0+SxikizgV2oJiY8FFgY+B1wHbAYuCUzPxp2TbS/8OtxQIlSeNQXlt6Atg/M69uWbcFxWjmRwFbAf/snXvj4zUoSRqf7Slmo141uKK8/nR/Zl4I/E/gcYpBYzUOFihJGp+7gIeAL5c3SDzn/0/LyT+/DbylE8H1AguUJI1DZq4E/g/wQmA+cHhEvKx83omI2IDiDj7nghonr0FJ0hqIiFdTTFJ4APAksIDijr59gKXAezPz5s5F2L0sUJLUBuUt528FDgSeojhzujAzf9vJuLqZBUqS2mxweKNOx9HtLFCSpEbyJglJUiNZoCRJjWSBkiQ1kgVKktRIFihJUiNZoCRJjWSBkiQ10v8HFBDNBjb5uo8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from qiskit.tools.visualization import plot_histogram\n",
    "from qiskit_aer.primitives import Sampler\n",
    "\n",
    "sampler = Sampler()\n",
    "\n",
    "job = sampler.run(qc_S)\n",
    "result = job.result()\n",
    "\n",
    "dist0 = result.quasi_dists[0]\n",
    "\n",
    "key_new = [str(key/2**m) for key in list(dist0.keys())]\n",
    "dist1 = dict(zip(key_new, dist0.values()))\n",
    "\n",
    "fig, ax = plt.subplots(1,2)\n",
    "plot_histogram(dist0, ax=ax[0])\n",
    "plot_histogram(dist1, ax=ax[1])\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d830d23",
   "metadata": {},
   "source": [
    "In the picture we have the same histograms but on the left we have on the x-axis the string with phase bits $\\varphi_1$, $\\varphi_2$ and on the right the actual phase $\\varphi$ in decimal representation.\n",
    "\n",
    "As we expected we have found $\\varphi=\\frac{1}{4}=0.25$ with a $100\\%$ probability."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2314dbb2",
   "metadata": {},
   "source": [
    "## IPE example with a 2-qubit gate\n",
    "\n",
    "Now, we want to apply the IPE algorithm to estimate the phase for a 2-qubit gate $U$. For this example, let's consider the controlled version of the $T$ gate, i.e. the gate $U=\\textrm{Controlled-}T$ (that from now we will express more compactly with $CT$). Its matrix is\n",
    "$$ CT = \n",
    "\\begin{bmatrix}\n",
    "1 & 0 & 0 & 0\\\\\n",
    "0 & 1 & 0 & 0\\\\\n",
    "0 & 0 & 1 & 0\\\\\n",
    "0 & 0 & 0 & e^\\frac{i\\pi}{4}\\\\ \n",
    "\\end{bmatrix} $$\n",
    "That is, the $CT$ gate adds a phase $\\pi/4$ to the state $|11\\rangle$, leaving unchanged the phase of the other computational basis states $|00\\rangle$, $|01\\rangle$, $|10\\rangle$.\n",
    "\n",
    "Let's consider to estimate the phase $\\phi=\\pi/4$ for the eigenstate $|11\\rangle$, we should find $\\varphi=1/8$, since $\\phi = 2 \\pi \\varphi$. Therefore to estimate the phase we need exactly 3 classical bits, i.e. $m=3$, since $1/2^3=1/8$. So $\\varphi=0.\\varphi_1\\varphi_2\\varphi_3$.\n",
    "\n",
    "As done with the example for the 1-qubit $U$ operator we will go through the same steps but this time we will have $3$ steps since $m=3$, and we will not repeat all the explanations. So for details see the above example for 1-qubit $U$ gate.\n",
    "\n",
    "First, we initialize the circuit with 3 qubits, 1 for the auxiliary qubit and 2 for the 2-qubit gate, and 3 classical bits to store the phase bits $\\varphi_1$, $\\varphi_2$, $\\varphi_3$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c13208f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "nq = 3    # number of qubits\n",
    "m = 3    # number of classical bits\n",
    "q = QuantumRegister(nq,'q')\n",
    "c = ClassicalRegister(m,'c')\n",
    "\n",
    "qc = QuantumCircuit(q,c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8107bb94",
   "metadata": {},
   "source": [
    "### First step\n",
    "\n",
    "Now we build the quantum circuit for the first step, to estimate the least significant phase bit $\\varphi_m=\\varphi_3$.\n",
    "\n",
    "#### Initialization\n",
    "\n",
    "We initialize the auxiliary qubit and the other qubits with the eigenstate $|11\\rangle$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "982d416d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH0AAADWCAYAAAD8W40IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKKElEQVR4nO3dfUwUiRnH8d/MAiJBDwxBo7tuBVmiq3AnVglNAK8WMaEBzzdIS5SSyIm9BLX1rlGMFI6cL21Jm6baGrXJ9WjiFiw1SMNFWDAQLXriW+KKLtJVKr5sFKMsuLv9g4iiIrNklpnheT4J/4xh59GvM7ss+iB4vV4vGCmi0gOw8cfRCeLoBHF0gjg6QRydII5OEEcniKMTxNEJ4ugEcXSCODpBHJ0gjk4QRyeIoxPE0Qni6ARxdII4OkEcnSCOThBHJ4ijE8TRCQpQegC1q2oD7jiVOfescOCTxfI/LkcfxR0ncLNH6Snkxbd3gjg6QRydII5OEEcniKMTxNEJ4ugEcXSCVB3d4/HgwIEDiImJQXBwMOLj42G1WhEbG4tNmzYpPd47WcpSce5EmeTjSlD127D5+fmoqqpCcXExEhIS0NLSgpycHNy/fx/btm1TejzNUm30yspKHDt2DI2NjUhJSQEALFu2DBcuXEBVVRUWLVqk8ITapdrbe3l5OdLT04eCvzR37lwEBgYiLi4OANDZ2YmUlBSYTCYsXLgQzc3NSoyrKaqM7nA4cOXKFaxdu/atX+vq6oLZbMakSZMAAAUFB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mRkJK5fv47t27crPY5sOPp7VFdX4+7du9Dr9bBYLEqPIxuOPoqgoCBkZ2ejulodWyTkwNHfobe3F93d3QAGn9NrampgNpsVnko+/CXbO/T29iIzMxMulwsejwdLly7Frl27lB5LNvwlm4+8Xq/mX8nz7d1H1rPt+NuJerzQ8FYMzUe/fPkyVq9ejYiICAQHByMmJgY7d+70y7lcrn40nW1H/8ALBOh0fjnHeND0c/r58+eRnJwMg8GA/fv3w2g0wm63o6WlxS/na7lwFc/6XFj+A3WuHZdK08/pqampuHbtGm7cuDH0DppUX+z9s5+mUsZXn0v/oQeavb0/e/YMzc3NyMnJ8Tk4dZq9vTudTng8Huj1+jF9vi9XhsvVj70HK2GYGYm8tSvHdD410Wz08PBwiKKIO3fujOnzx3J7v37rv6p9WiBxew8JCUFycjIqKyvx5MkTpcfRFE2/kHv56t1oNGLHjh0wGo3o6upCc3MzDh8+LMs5Glq/w7+b/oMtuVkwzIyU5TGVptnbOzC49721tRXFxcXYunUr+vr6YDAYkJ2dLcvju1z9aD53CbFRhgkTHND4le5v3T0P8fWJemRnfMzRKfF4PBB9+GkMWsDRCZpYf4WZJBydII5OEEcniKMTxNEJ4ugEcXSCODpBHJ0gjk4QRyeIoxPE0Qni6ARxdII4OkEcnSCOThBHJ4ijE8TRCeLoBHF0gjg6QRydII5O0P8BTmvlWmCsIVAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 146.797x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc.h(0)\n",
    "qc.x([1, 2])\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "739dbd79",
   "metadata": {
    "tags": []
   },
   "source": [
    "#### Application of the Controlled-$U$ gates\n",
    "\n",
    "Then we have to apply multiple times the $CU$ operator, that, in this example, is the Controlled-$CT$ gate ($CCT$ for short).\n",
    "\n",
    "To implement $CCT$ in the circuit, since $T$ is a phase gate, we can use the multi-controlled phase gate $\\text{MCP}(\\theta)$, with $\\theta=\\pi/4$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "280518a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKoAAACoCAYAAABwvnWJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAK0klEQVR4nO3dXWxUdRrH8e9MoYDU3UJqUOlSaOkIDDJFBLFBKAaxGrKwgi+Q7SJpYrXGhJi9MsGEYMhKSCQxgF4YTdhsdyPp3hgsurEvIDVYhUEapUBbSgvLm1SlyIDt7MXAlBZK29U55zzD75NMsGdO2//gl3PmNJ15fNFoNIqIx/ndXoDIQChUMUGhigkKVUxQqGKCQhUTFKqYoFDFBIUqJihUMUGhigkKVUxQqGKCQhUTFKqYoFDFBIUqJihUMUGhigkKVUxQqGKCQhUTFKqYoFDFBIUqJihUMUGhigkKVUxQqGKCQhUTFKqYoFDFBIUqJihUMUGhigkKVUwY4vYCZHB+uQynDsHF78E/BO7Kgd/d7faqEs/TR9Suri42btxIbm4uw4cPJxQKUV1dzX333ccLL7zg9vIc13YAdm2Fb3fCsS+hqRb2/h2+LIPIBbdXl1ieDrW4uJh169ZRUlLCxx9/zDPPPMPy5ctpbGxkxowZbi/PUSfq4dtPoPPKjff9cAK++lfsaJusPHvqLysr44MPPqCqqop58+YBMH/+fL7++mvKy8t54IEHXF6hc7o64Uj1LXaIwsXzcOIgjEvSvxbPHlHXr19PYWFhPNJrJk6cyNChQ5k2bRoAzc3NzJs3j0AgwP3338+uXbvcWG5Cfd8Mly/2v1/bgYQvxTWeDLW1tZWDBw/y9NNP33BfS0sLwWCQYcOGAVBSUsKzzz5LQ0MD7777Ls899xyXL/d/DvT5fGZuq/784oD+3k4db3d9rYO9DZRnQwW4++6el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Q2Ufd/pg2Eh4aCWkJunAGM+e+gcytPf8+fMsWrSIQCBAKBRi4cKFHDmSfMPrO3+5eiTtSzT2lODEAceW5DhPhjrQob0+n4/Vq1fT0NBAOBxm0aJFrFq1yoUVJ9a5Jvgl0v9+Jw4mfi1u8Wyo0PfQ3msjfNLT01mwYEH8/vz8fJqamgb0PdyeqjyYW/FfXhzQYzp9ot31tSZqurQnQ71+aO/1+hvau2nTJpYsWZLo5Tnuh46z/e4TjXbxY8c5B1bjDk9e9f8/Q3vXrl3LkSNH+Oyzzwb0PTx6DXlTnVegZkvsz774fH7m/DGH6N/sPK7B8OQRdbBDe9944w0++ugjKioquOOOO1xadeKkDIXxD91iBx8MHQFjQ44tyXGe/fHUzRQVFREOhzlwoPvydu3atezYsYOdO3eSnp7u3uISLBqFw9XQUnd1w7Wnd9HY4N7py2KDfZOVqVAnT57M7Nmzef/994HYGyhMnTqVnJwc0tLS4vtd/+5zyabj+9iPoTrOQ8qQ2OjzMQHwe/JJ3G/HzMO7NrS3tLQ0vi0YDJp6rvlbGDkacgvcXoXzTB1R5fblyYspkd4UqpigUMUEhSomKFQxQaGKCQpVTFCoYoJCFRMUqpigUMUEhSomKFQxQaGKCQpVTFCoYoJCFRMUqpigUMUEhSomKFQxQaGKCQpVTFCoYoJCFRMUqpigUMWE/wEwnllIOYnWZwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 206.997x204.68 with 1 Axes>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cu_circ = QuantumCircuit(nq)\n",
    "cu_circ.mcp(pi/4, [0, 1], 2)\n",
    "cu_circ.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd174450",
   "metadata": {},
   "source": [
    "Let's apply $2^t$ times $\\text{MCP}(\\pi/4)$. Since for the first step $t=m-1$ and $m=3$, we have $2^t=4$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "24c8f9b9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nnzySbfLEhGRTkSXWbVRKBTSGd0iItLhNMTdRvmfFfK/319LfSDgdikiIuJhER/QO3bs4L777iMuLo5u3bqRnJzME0880SHrqqmpZf1nhdTW1RPl93fIOkRERCDCj0Fv3ryZSZMmkZCQwHPPPUdiYiLFxcUUFBR0yPoKtuziQnUNd34ns0MeX0RE5GsRfQw6Ozub3bt3s3fv3oZP/mqtXz37WgdVJSIicmW/++W8Vi0XsUPcFy5cYMOGDcyaNavN4SwiImK6iB3iLi8vJxgMMmjQoKv6/dZuwYB97PnZPy4jYWA/5s6466rWJyIi0hYRG9B9+vTB5/Nx6NChq/r9qxni3rO/VEPjIiJyTTw/xB0TE8OkSZNYtmwZ586dc7scERGRdhXRJ4l9fRZ3YmIijz/+OImJiZSUlLBhwwZef/31dlnHuk+28uH6z1kwezoJA/u1y2OKiIiEE7FD3ACZmZl88sknLFq0iF/84hdUV1eTkJDAzJkz2+Xxa2pq2fCP7aQmJSicRUTEURG9B93Rjhw/xTvvr2XmPbcroEVExFEK6DCCwSA+X8QeqhcRkQilgBYRETGQdg1FREQMpIAWERExkAJaRETEQApoERERAymgRUREDKSAFhERMZACWkRExEAKaBEREQMpoEVERAykgBYRETGQAlpERMRACmgREREDKaBFREQMpIAWERExkAJaRETEQApoERERAymgRUREDKSAFhERMZACWkRExEAKaBEREQMpoEVERAykgBYRETGQAlpERMRACmgREREDKaBFREQMpIAWERExkAJaRETEQP8fyJf28KUOf5wAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 628.397x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for _ in range(2 ** (m - 1)):\n",
    "    qc.mcp(pi/4, [0, 1], 2)\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09e40686",
   "metadata": {},
   "source": [
    "#### Measure in X-basis\n",
    "\n",
    "Finally, we perform the measurement of the auxiliary qubit in X-basis.\n",
    "We can use the `x_measurement` function defined above in the example for 1-qubit gate. In this way we have obtained the phase bit $\\varphi_3$ and stored it in the classical bit $c_0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6fa62739",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkMAAADWCAYAAADSDYZCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgk0lEQVR4nO3de3RU9d3v8ffM5AIhXA13QiDkggSSQIRykwRUxGpBUSq0h4WIxSK2pdan9ah4KT6sgmg5elovj6i1PqXngOChLoTaShIoVA2QGOQSkEAuBMM9CZCQZOb8sSEhEDITSGbPzP681trLmd/s2fubH+Psz/z2b/bYXC6XCxERERGLsptdgIiIiIiZFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE0oLMLsDXrcmC4lPm7Lt3Z5h6izn7FhGR1uevx5gFCxaQnZ3dovV4Ijk5meXLl7f4dhWG3Cg+Bd+Wml2FiIgEIn89xmRnZ5ORkWF2GS1Gp8lERETE0hSGRERExNIUhkRERMTSFIZERETE0hSGRERExNIUhkRERMTSFIZERETE5wQHB3ttX7rOkIiIiLSaNm3aMHHiRIYPH87gwYMJCwujsrKSPXv2kJWVxYYNG6ioqLjqOevWrSMrK4unn3661WtUGBKvcrnAZjO7isDnchn/VV+3PvW196iv/UvHjh15+umnmTNnDjfddNNVj0+ePBmAsrIyPvjgAxYtWkRpaWldELrjjjsYMmQIy5cvp7S0da9M6dNhyOl08uqrr/LWW29RWFhIf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QUFbN68mXfeeadF9rFp2042Zn7F/Jn3EtmrW4tsU0RERHyH354mA0hJSWHbtm0sXLiQX/7yl1RWVhIZGcn06dNbZPtVVRfY/OXXxEdHKgiJiIgEKL8eGWptJaUn+PDjz5h+zwSFIRERkQClMOSG0+n0mStkioiISMtTGBIRERFL05CHiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhYmsKQiIiIWJrCkIiIiFiawpCIiIhY2v8HzfadmajGaAwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 748.797x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_measurement(qc, q[0], c[0])\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ac0df28",
   "metadata": {},
   "source": [
    "### Subsequent steps (2nd, 3rd)\n",
    "\n",
    "Now we build the quantum circuit for the other remaining steps, the second and the third ones.\n",
    "As said in the first example, in these steps we have the additional sub-step of the phase correction.\n",
    "\n",
    "#### Initialization with reset\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1520c0da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAp4AAADWCAYAAAB44oK7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAi4UlEQVR4nO3deXhU9eHv8c/MZIEQViOyhUCABAkkgQgCIgmoiNWCGxXa8gBioYjtj1q361Kl+KOCaLl6W5cratVbei8ISi2CtJKAhSoBEoICAQlkIcieBQiQzNw/BhICITMhyffMTN6v5zmPM2fOzHz4euB8crbYXC6XSwAAAEAjs1sdAAAAAE0DxRMAAABGUDwBAABgBMUTAAAARlA8AQAAYATFEwAAAEZQPAEAAGAExRMAAABGUDwBAABgBMUTAAAARlA8AQAAYATFEwAAAEZQPAEAAGAExRMAAABGUDwBAABgBMUTAAAARlA8AQAAYATFEwAAAEZQPAEAAGAExRMAAABGUDwBAABgBMUTAAAARlA8AQAAYATFEwAAAEZQPAEAAGAExRMAAABGBFkdwNctS5cKjlvz3Z3bSvfeYM13AwAan79uY2bNmqWMjIwGzeONxMRELVy48Krea1VmqX65rVpHGquDUDw9KDgufX/I6hQAgEDkr9uYjIwMpaWlWR2jTvwxs+S/68iVcKgdAAAARlA8AQAAYATFEwAAAEZQPAEAAGAExRMAAABGUDwBAABgBMUTAAD4nODgYKsjoBFwH08AANBomjVrplGjRmngwIHq27evwsLCVFZWph07dig9PV2rVq1SaWnpZe9ZsWKF0tPT9fTTT1uUHI2B4gmjXC7JZrM6ReBzudz/ZawbH2NtDmPtX1q3bq2nn35aU6dO1TXXXHPZ62PGjJEkFRcX64MPPtCcOXN06NChytJ52223qV+/flq4cKEOHQqgO6g3cT5dPJ1Op1599VW99dZbysvLU2xsrF577TVNmzZNycnJevvtt62OeJmlL6aoa99bNejuZ72a3xScKJByN0tH9krOCimsrdQlUercT3JwJKVBHcmR8rZIx/ZLcknh10pd+ksd+0h2h9XpAofLJR3KlvK2SkUH3PNadZQi+0vXxVKMGpLTKR38zj3WpYck2aS2kVLXAVJED6vTmecv25jbb79dixYtUufOnSVJmzdv1urVq5WRkaGioiKFh4crISFBI0eO1LBhw/TII49owoQJ+q//+i9NmjRJt912mw4ePKiRI0caLZ2TJk3S5MmTNWLECK+Wv7BH9osvvmjkZN7z9XXEp4vn1KlTtWzZMj333HNKSkrShg0bNGHCBB0+fFiPPvqo1fHghbyt0q5/SbJJOr+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5cgU5aj8sAAAA3Gw2m+4dfbPCw5pLkkJCgvWTO1Nkt/t9DUEd+fXtlDZv3qzhw4crMjJSL7/8sqKiopSTk6MNGzY0yvdt2PKtTpWd0a03JTXK5wMAEKjCw5rr3juG64OPV+vHtwxRuzatrI4EC/j1OZ4pKSn67rvvtHv37srfNOStp+a93UipAAAAmpaXnpzm1XJ+u4/71KlTWr9+vSZMmFDn0gkAAADz/PZQ+/Hjx+V0Oq/6BrLeNnPJfW7nvDcXK7JTe00Zd8dVfR8AAEBT57fFs23btrLb7SooKLiq91/NofZde/M4RA8AAHCJgD/UHhYWpuHDh2vx4sUqLi62Og4AAAA88OuLiy5c1R4VFaUnnnhCUVFRys3N1fr16/XOO+80yHes3bhVq9dt0syJdyuyU/sG+UwAAICmyG8PtUtSUlKSNm7cqOeee06/+c1vVFZWpsjISI0fP75BPv/MmbNa/802xUZHUjoBAADqya/3eDa2wkNH9dEnazT+rpEUTwAAgHqieHrgdDr5zQoAAAANgOIJAAAAI9iVBwAAACMongAAADCC4gkAAAAjKJ4AAAAwguIJAAAAIyieAAAAMILiCQAAACMongAAADCC4gkAAAAjKJ4AAAAwguIJAAAAIyieAAAAMILiCQAAACMongAAADCC4gkAAAAjKJ4AAAAwguIJAAAAIyieAAAAMILiCQAAACMongAAADCC4gkAAAAjKJ4AAAAwguIJAAAAIyieAAAAMILiCQAAACMongAAADCC4gkAAAAj/j8pDro0Ulg3+QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 869.197x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc.reset(0)\n",
    "qc.h(0)\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7da1b6a",
   "metadata": {},
   "source": [
    "#### Phase correction (for step 2)\n",
    "In order to extract the phase bit $\\varphi_{2}$, we perform a phase correction of $-\\pi\\varphi_3/2$.\n",
    "\n",
    "So, after the reset we apply the phase gate $P(\\theta)$ with phase $\\theta=-\\pi/2$ conditioned by the classical bit $c_0$ ($=\\varphi_3$)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "99a64b7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAswAAADWCAYAAADFA9TOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAncUlEQVR4nO3deXxTdaL+8SdJS6GU1cpSKIUCLUOhLZsDCLQgMDCjoCgKKj9g8MJFnRkc1+vuoAzgMly9jqMjyqgj3guiMAyiqLTggA4FWgooBSl0oezQBWhLk/z+CLRUyklL25wk/bxfr/MyOTlJHr4eyJOTb04sTqfTKQAAAABVspodAAAAAPBmFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADFGYAAADAQIDZAbzdihQp95Q5z92hlTShvznPDQCof776GjNnzhylpqbWaZ7qiI+P16JFi67qvmZllmqX26x9pDb7x56vpcKjdZunupq1kaJH1P3jUpjdyD0l/WjS/3QAgH/z1deY1NRUJScnmx2jRnwxs+Sb+0jhUel0jtkp6hZTMgAAAAADFGYAAADAAIUZAAAAMEBhBgAAAAxQmAEAAAADnCUDAAAApnrwjUR9f3CzbLZAWa02tW8dqbtueFJDY281O5okjjADAAAvFBgYaHYEeNhdI5/SP14o0opnT2h4/GQ9//c7lHMsw+xYkjjCDAAA6lHjxo01evRoDRgwQL169VJwcLCKi4v1/fffKyUlRWvXrlVRUdFl91m1apVSUl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rbtm0qKirSxo0bVVpaqi1btly2zcCBA5WWlmZCustRmAEAAOBR3377rUaNGiVJGjlypDZv3qyHH35YDodDY8aMUVZWllq1aqWgoCCTk7pQmAEAAOBRp0+fLj/HcosWLXT69GkdOXJEM2fO1E033aROnTqZnLCyALMDAAAAoGFp0aKFCgoKJEkFBQVq2bKlZs2apbFjx+r11183Od3lOMIMAAAAjxo0aJC++uorSdKXX36pgQMHau7cuXrmmWc0f/58k9NdjsIMAAAAj+rbt68aN26soUOHymazadOmTbrlllv04IMPKj09Xbt27VJKSopGjhypnTt3auTIkSouLjYtL7/0BwAAABjgCDMAAABggMIMAAAAGKAwAwAAAAYozAAAAIABCjMAAABggMIMAAAAGKAwAwAAAAYozAAAAIABCjMAAABggMIMAAAAGKAwAwAAAAYozAAAAIABCjMAAABggMIMAAAAGKAwAwAAAAYozAAAAIABCjMAAABg4P8DaURrkk7Dm34AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 929.397x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc.p(-pi/2, 0).c_if(c, 1)\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68be63a1",
   "metadata": {},
   "source": [
    "#### Application of the Control-$U$ gates and x-measurement (for step 2)\n",
    "We apply the $CU$ operations as we did in the first step. For the second step we have $t=m-2$, hence $2^t=2$. So we apply $\\text{MCP}(\\pi/4)$ $2$ times. And then we perform the X-measurement of the qubit $q_0$, storing the phase bit $\\varphi_2$ in the bit $c_1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "fa0d6cef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA9wAAADWCAYAAAAjI4rmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o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IyMjRy5Eht2bJFI0eO1Llz56yODQB1ZnO5XC6rQwAAAAAAEGg4ww0AAAAAgAkouAEAAAAAMAEFNwAAAAAAJqDgBgAAAADABBTcAAAAAACYgIIbAAAAAAATUHADAAAAAGACCm4AAAAAAExAwQ0AAAAAgAkouAEAAAAAMAEFNwAAAAAAJqDgBgAAAADABBTcAAAAAACYgIIbAAAAAAATUHADAAAAAGACCm4AAAAAAExAwQ0AAAAAgAn+H4D1Rj6bGM5JAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 1290.6x264.88 with 1 Axes>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for _ in range(2 ** (m - 2)):\n",
    "    qc.mcp(pi/4, [0, 1], 2)\n",
    "x_measurement(qc, q[0], c[1])\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25949dc2",
   "metadata": {},
   "source": [
    "#### All substeps of the 3rd step\n",
    "For the 3rd and last step, we perform the reset and initialization of the auxiliary qubit as done in the second step.\n",
    "\n",
    "Then at the 3rd step we have to perform the phase correction of $-2\\pi 0.0\\varphi_{2}\\varphi_{3}= -2\\pi \\left(\\frac{\\varphi_2}{4}+\\frac{\\varphi_3}{8}\\right)=-\\frac{\\varphi_2\\pi}{2}-\\frac{ \\varphi_3\\pi}{4}$, thus we have to apply 2 conditioned  phase corrections, one conditioned by $\\varphi_3$ ($=c_0$) and the other by $\\varphi_2$($=c_1$). To do this we have to apply the following:\n",
    "- gate $P(-\\pi/4)$ conditioned by $c_0=1$, that is, by $c=001$ (``c_if`` with value $1$)\n",
    "- gate $P(-\\pi/2)$ conditioned by $c_1=1$, that is, the gate is applied when $c=010$ (``c_if`` with values $2$)\n",
    "- gate $P(-3\\pi/4)$ conditioned by $c_1=1$ and $c_0=1$ that is, the gate is applied when $c=011$ (``c_if`` with values $3$)\n",
    "\n",
    "Next, the $CU$ operations: we apply $2^t$ times the $\\text{MCP}(\\pi/4)$ gate and since at the 3rd step $t=m-3=0$, we apply the gate only once."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "fee5769f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABMAAAAG5CAYAAABoX0g4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAABTPElEQVR4nO3deXhTZcL+8TtJN6BAgcrWlkKhBSm0hQICAi0IiI6KGyo4jDI48APHV1BH3HBcGUBU1NdxeQfFZcQZEBUdZUSlpQgqBVopKAVZSqEssrYs3ZLfH4FC6ZIU2pzk9Pu5rnOZnpwkdx9DnvTOOScWh8PhEAAAAAAAAGBSVqMDAAAAAAAAAHWJAgwAAAAAAACmRgEGAAAAAAAAU6MAAwAAAAAAgKlRgAEAAAAAAMDUKMAAAAAAAABgahRgAAAAAAAAMDUKMAAAAAAAAJgaBRgAAAAAAABMjQIMAAAAAAAApkYBBgAAAAAAAFOjAAMAAAAAAICpUYABAAAAAADA1CjAAAAAAAAAYGoUYAAAAAAAADA1CjAAAAAAAACYGgUYAAAAAAAATI0CDAAAAAAAAKZGAQYAAAAAAABTowADAAAAAACAqVGAAQAAAAAAwNQowAAAAAAAAGBqFGAAAAAAAAAwNQowAAAAAAAAmBoFGAAAAAAAAEyNAgwAAAAAAACm5md0AG+3OF3afdiYxw5rJt3Yy5jHBgDUPV+dY6ZMmaKMjIxazeOOhIQEzZ0794Jua1Rm6eJyG/UcuZjnx+Zvpfz9tZvHXY1bSp2HGPPYgLdhjqkZ5hjPqY9zjFG5fTGzVHfzOQWYC7sPS78a9D8dAGBuvjrHZGRkKDU11egYNeKLmSXffI7k75eO5BqdAoAvvn5Ivvl67YuZJd98jvjqHOOLuX0xsyscAgkAAAAAAABTowADAAAAAACAqVGAAQAAAAAAwNQowAAAAAA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wKSRMyll79ps1A4Odn3C26+ncowYXz2qT4kZKuzOc30B44vT7qgZNnW+UwxOc2+Di2QKknqOkXeuc3ypb6DxaQI1aOJ/TbbvXv0/mvXWO+etf/6o2bdpo48aN1W43bdo0l+WX5DzFwR/+8AcdPHiwLuK6bebMmWrWrJnWrFmjwMBALVu2TL///e/Lrh8+fLjWr19veM5zeetzBO6xWKTYq6VmEVLOOun4b871gY2liATnXq82r3337lusflLCjc65fNd66dTpUzE1bOacz8Pi6+fe3N74GjJ79mwtWLBA6enp1W537733uiy/JOd5pP/whz+UHYZoFOYYwPN8agpNT09X3759y617/fXXdeedd2ru3LkKCAjQggULFBDAX/repGWMc/l6jvPngZPr5xuKumaxOPeGaRMrffO8c92AifWvIPAEq/V02dXj7Fj3v4uxrgs2f6n9ZVJkn7Nj3fcOxtrbfPPNN25td88992j//v2aNWtWleWXJB0/flzvvfdebcW7YHa7XX/5y1/0l7/8pdLrOTQFdcFice4J1rb7OfP5BF736oLV5vxAtl3i2bHu90fG2tu4e6L6hx9+WCdPntTcuXOrLL8kqaioiDkGqKd8pgArKChQdna2Jk+eXG59VFSUYd/egQtD+VW3zn3Txhu4usVYew5jbQ5FRUWaPn260TFqzc6dO7Vw4UKjY5jab0d364WFd+n4qaOyWKzqHNFbk6570ehYHsHrnucw1uZQWlrqVd+WeLGYY+reb0d3698pz2nyyLmSpI9WvKi0DR9p7t0rjQ1WDW+cF7fvzdLcRRNktdrUtkUnPXDLW7JU8WJ6ZswH9xit15dM9fjv4DMFWHBwsEpL69/XEAMAAM/IyMjQ/Pnz3d7+ySefrLswkCStzV6mK3r+XgO736QA/yD97YPbtT1vgzq06e76xgDgRZhjvM/a7GVKjHGelLqopFC/7skwNpAbvHFejLiks1768ypJ0nP/Gqfs3HR1juhd6bZnxrxVSKSem/itx38HnynAAAAA6lJmZqYyMzONjlEvZf6aoifeuUFRbeK199B2dWyboKfGfaqftqXqz9e/ogD/IEmSzeovKydaBOCDmGOM42qOkaSlP87TsF536J3/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AAAADA1CjAAAAAAAAAYGoUYAAAAAAAADA1CjAAAAAAAACYGgUYAAAAAAAATI0CDAAAAAAAAKZGAQYAAAAAAABTowADAAAAAACAqVGAAQAAAAAAwNQowAAAAAAAAGBqFGAAAAAAAAAwtf8P2GCcMgwDJu0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 1591.6x565.88 with 1 Axes>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# initialization of qubit q0\n",
    "qc.reset(0)\n",
    "qc.h(0)\n",
    "\n",
    "# phase correction\n",
    "qc.p(-pi/4, 0).c_if(c, 1)\n",
    "\n",
    "qc.p(-pi/2, 0).c_if(c, 2)\n",
    "qc.p(-3*pi/2, 0).c_if(c, 3)\n",
    "\n",
    "# c-U operations\n",
    "for _ in range(2 ** (m - 3)):\n",
    "    qc.mcp(pi/4, [0, 1], 2)\n",
    "\n",
    "# X measurement  \n",
    "qc.h(0)\n",
    "qc.measure(0, 2)\n",
    "\n",
    "qc.draw('mpl')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f32900a5",
   "metadata": {},
   "source": [
    "Now, we execute the circuit with the simulator without noise."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c6e0a06f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAdIklEQVR4nO3dfZQcdZ3v8fcHQgQkIg8SSEIIkdkgUQQZCQ8XGJQowj05PHh4UEDwQgxRFKOucC+KQcFVEGFZuUJWjWFxlwVFcAVh5TI8BjBBsvK4gAkyQwgEEBAIgeR7/6gaaJru6aqZnu7q7s/rnDrT/atf1XyH9JdvV9Wv6qeIw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
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "result = sampler.run(qc).result()\n",
    "dist0 = result.quasi_dists[0]\n",
    "\n",
    "key_new = [str(key/2**m) for key in list(dist0.keys())]\n",
    "dist1 = dict(zip(key_new, dist0.values()))\n",
    "\n",
    "fig, ax = plt.subplots(1,2)\n",
    "plot_histogram(dist0, ax=ax[0])\n",
    "plot_histogram(dist1, ax=ax[1])\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a992b916",
   "metadata": {},
   "source": [
    "We have obtained $100\\%$ probability to find $\\varphi=0.125$, that is, $1/8$, as expected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "7280b7b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td><code>qiskit-terra</code></td><td>0.23.0.dev0+1b4fed3</td></tr><tr><td><code>qiskit-aer</code></td><td>0.11.1</td></tr><tr><td><code>qiskit-nature</code></td><td>0.5.0</td></tr><tr><th>System information</th></tr><tr><td>Python version</td><td>3.9.13</td></tr><tr><td>Python compiler</td><td>Clang 12.0.0 </td></tr><tr><td>Python build</td><td>main, Oct 13 2022 16:12:30</td></tr><tr><td>OS</td><td>Darwin</td></tr><tr><td>CPUs</td><td>4</td></tr><tr><td>Memory (Gb)</td><td>32.0</td></tr><tr><td colspan='2'>Fri Dec 09 16:18:07 2022 CET</td></tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2022.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import qiskit.tools.jupyter\n",
    "%qiskit_version_table\n",
    "%qiskit_copyright"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
